package com.example.bookmall.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // 创建分页拦截器并设置数据库类型
        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
        // 根据你的实际数据库类型选择，常见的有：
        // DbType.MYSQL, DbType.POSTGRE_SQL, DbType.ORACLE 等
        paginationInterceptor.setDbType(DbType.MYSQL);

        // 设置溢出处理（可选）
        paginationInterceptor.setOverflow(true);

        interceptor.addInnerInterceptor(paginationInterceptor);
        return interceptor;
    }
}

